home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / basic / Crazy8.src.lha / Scource / Crazy2.8.asc < prev    next >
Text File  |  1999-02-01  |  62KB  |  2,096 lines

  1. ; Crazy 8's
  2. ; Ver 2.8
  3. ; by Curt Esser
  4. ; 113 Pauline Ave
  5. ; Crystal Lake
  6. ; Il. 60014
  7. ; camge@ix.netcom.com
  8. ; last modified  1/28/98
  9.  
  10.  
  11. WBStartup                          ;run from WorkBench!
  12. v$="$VER: Crazy8 v2.8 (28-01-99) by Curt Esser"
  13. ScreenPens 1,4,0,3,7,3,3
  14.  
  15. If NTSC=True
  16.   vrate=60      ;adjust for NTSC or PAL Vblank rate
  17. Else
  18.   vrate=50
  19. EndIf
  20.  
  21. ;---------------------------------------------------------------
  22.  
  23. ourpath$=ProgDir$  ;get our program's directory
  24.  
  25. ;----------------------------------------------------------------
  26. ; fade the current screen to a new palette
  27. Statement fadeto{palobj,speed}     ;speed must be 1+
  28.   PaletteInfo palobj
  29.   For i = 0 To 15                  ;number of available colour steps
  30.    For j=0 To 7                    ;number of currently used colours
  31.     rd = Red(j)
  32.     If rd < PalRed(j)  Then rd+1   ;check each for the difference
  33.     If rd > PalRed(j) Then rd-1    ;between current colour and
  34.     bl = Blue(j)                   ;the target colour
  35.     If bl < PalBlue(j)  Then bl+1  ;and reset as needed
  36.     If bl > PalBlue(j) Then bl-1
  37.     gr = Green(j)
  38.     If gr < PalGreen(j) Then gr+1
  39.     If gr > PalGreen(j) Then gr-1
  40.     RGB j,rd,gr,bl                 ;and reset current screen
  41.    Next j
  42.    VWait speed                     ;take out if too slow or
  43.   Next i                           ;increase if too fast
  44. End Statement
  45. ;----------------------------------------------------------------
  46.  
  47. ntsSys=NTSC                        ;True if a NTSC system
  48. Forced.b=0                         ;if display was forced
  49.  
  50. ;Some constants for use when setting FNSPrefs
  51. #none=0
  52. #centred=%1
  53. #bold=%10
  54. #underline=%100
  55. #rightalign=%1000
  56. ;Install our font as number 1
  57. #font=1
  58. suc.l=InstallFNS(#font,?font_dat)
  59. ;suc.l=FNSLoad("Windy.FNS",#font)
  60.  
  61. ;If suc.l doesn't equal #font then an error occured
  62. If suc<>#font Then Request Str$(suc),"Can't Load Font","Damn" : End
  63.  
  64. ;-----------------------------------------------------------------
  65.  
  66. wb.w=WBWidth                       ;how wide is user's screen?
  67. If wb>720 Then wb=720              ;check for oversized bench
  68. wb=Int(wb/2)                       ;divide for our lo-res screen
  69. ofst.b=Int((wb - 320)/2)           ;and get horizontal to center it
  70.  
  71. .Loadup
  72. MaxLen newmod$=192                 ;for selecting new module
  73. MaxLen fi$=255                     ;filename $
  74. MaxLen pa$=255                     ;mod path $
  75. MaxLen snd$=255                    ;sounds path $
  76. MaxLen newsnd$=255
  77.  
  78. BitMap 0,320,200,3                 ;lo-res 8 colors page
  79. BitMap 1,320,200,3                 ;double buffered drawing page
  80. InitPalette 0,8                    ;set a palette to black
  81. Screen 0,ofst,0,320,200,3,0," Crazy 8's 2.7",0,0,0  ;open the screen
  82. Use Palette 0                      ;black screen to start
  83. Window 0,0,0,320,200,$1900," ",0,0 ;open our window
  84. ShowBitMap 1                       ;show blank page
  85. MenusOff                           ;we use no menus
  86. CatchDosErrs                       ;show system requestors on our screen
  87. LoadBitMap 0,"data/C8.Title",0     ;load the title screen pic
  88. SetCycle 0,0,2,5,.25               ;set up for color cycling
  89. ShowBitMap 0                       ;get title screen ready
  90. Cycle 0                            ;make letters on title "squirm"
  91. fadeto{0,2}                        ;and fade in the title screen
  92. Dim txt$(74)                       ;for text from locale file C8.LOCALE
  93. Gosub GetLocale                    ;load up the locale file
  94. Gosub loadpref                     ;and the prefs file
  95. hold.w=0                           ;used for message delay
  96. Use BitMap 0
  97. LoadBitMap 1,"data/C8.playscreen",1    ;load game screen & palette
  98. LoadPalette 2,"data/pal.pref"          ;load palette for options page
  99. LoadPalette 3,"data/pal.x"             ;load all grey palette for fades
  100. LoadPalette 4,"data/pal.green"         ;load the other screen palettes
  101. LoadPalette 5,"data/pal.grey"          ;for player to switch to
  102. LoadPalette 6,"data/pal.tan"
  103. LoadPalette 7,"data/pal.maroon"
  104. LoadPalette 8,"data/pal.purp"
  105. LoadPalette 9,"data/pal.purp2"
  106. LoadPalette 10,"data/pal.yelo"
  107. LoadPalette pl.b,"data/pal.pointer",16 ;load colors for the pointers
  108.  
  109. Dim sd$(33)                            ;for the 34 sounds
  110. Dim Timeout.w(33)                      ;and their mask time
  111. For i=0 To 33                          ;read them from data $
  112.   Read sd$(i)
  113. Next
  114.  
  115. ;Names for the sounds:
  116. Data$ "Laugh","aarrgghh!","awwww","NotCompute","clap"
  117. Data$ "drum","GameOver","scream","Shuffle","snare"
  118. Data$ "tankoo","uh-oh","spoit","tick","bell"
  119. Data$ "Cuckoo","Hey1","boom","Whoosh","BowArrow"
  120. Data$ "Cut.it.out","Girl.sigh","Glepuughn","Oooh","DaMeaning"
  121. Data$ "Spit","Yeah","Drip1","WhatDo","Carumba"
  122. Data$ "doh01","doh30","doh31","excellent"
  123.  
  124. Gosub LoadSounds
  125.  
  126. If Peek.l(Addr Sound(0))               ;make sure it's there!
  127.   Sound 0,1                            ;play the crazy laugh
  128.   VWait 12                             ;and echo it in
  129.   Sound 0,2                            ;the other speaker
  130. EndIf
  131.  
  132. SetErr
  133.  ShowBitMap 0                          ;make sure we're on the right bitmap
  134.  Use BitMap 0                          ;and put up a requestor
  135.  Request txt$(60),txt$(62),txt$(61)
  136.  StopMed
  137.  Quiet 15
  138.  End                                   ;and end program
  139. End SetErr                             ;that wasn't so hard!
  140.  
  141. LoadShapes 0,"data/card.shapes"        ;0=back 1-52 cards s/h/c/d
  142. LoadShapes 53,"data/newgad.shapes"     ;53=SetUp,exit,Play/54-57 cardflips
  143.                                        ;58 suit select/59 8 <-
  144.                                        ;60-63 s/h/c/d ;64 Quit Requestor
  145. LoadShapes 65,"data/pointer.shps"      ;65-67, normal,btn dwn,wait pointers
  146. Use BitMap 1                           ;use the unseen page
  147. Boxf 16,110,40,142,6                   ;draw a "blank" shape
  148. GetaShape 68,16,110,24,32              ;pick it up for erasing
  149. MidHandle 68                           ;and set its handle to center
  150. Boxf 16,110,40,142,0
  151. Use BitMap 0                           ;now use the title page
  152. If ModOn.b=1                           ;Load music mod if wanted
  153.    ld$=pa$+"/"+fi$                     ;make loading $
  154.    LoadMedModule 0,ld$                 ;load the music
  155.    music=1                             ;set the music on flag
  156. Else                                   ;if no module is to be loaded
  157.    music=0                             ;make sure the flag is off!
  158. EndIf
  159. VWait 120                              ;wait for the laugh to end
  160. Gosub MusicOn                          ;start music & set filter
  161.  
  162. ;======================================================================
  163.  
  164. SetInt 5                            ;countdown the timer
  165. If hold.w                           ;and play the music
  166.   hold-1
  167. EndIf
  168. If music=1                          ;only if the music is on
  169.  If hold=1 Then SetMedMask 15       ;if the sound is done, use all 4
  170.  PlayMed                            ;now play the next beat of music
  171. End If
  172. End SetInt
  173.  
  174.  
  175. ;======================================================================
  176.  
  177. .Initialize
  178. Dim Deck.b(52)    ;Deck of Cards
  179. Dim Pile.b(52)    ;Discard Pile
  180. Dim Phand.b(52)   ;Player's Hand  ( Card# )
  181. Dim Ppos.w(52,1)  ;Player Card Positions (x,y)
  182. Dim Chand.b(52,3) ;Computer's Hand (Card,playability,suit,rank)
  183. Dim scorename$(30)
  184. Dim gamesplayed(30)
  185. Dim gameswon(30)
  186. Dim winpct.w(30)
  187.  
  188. NEWTYPE.scores    ;for the listviews
  189.   pad.w
  190.   string.s
  191. End NEWTYPE
  192.  
  193. Dim List sndDrawers.scores(50)
  194.  
  195. complain.b=1      ;computer's complaints
  196. Split.b=0         ;end game flag
  197. Pscore.w=0        ;Player's Score
  198. Cscore.w=0        ;Computer Score
  199. Pcards.b=0        ;Cards in Player's Hand
  200. Ccards.b=0        ;Cards in Computer Hand
  201. Cspades.b=0       ;number of cards in each suit in
  202. Chearts.b=0       ;  computer's hand
  203. Cclubs.b=0
  204. Cdiamonds.b=0
  205. Cmost.b=0         ;suit computer has most of
  206. Compeight.b=0     ;how many 8's computer has
  207. mxx.b=0           ;maximum cards of any suit
  208. PlayCard.b=0      ;Card selected for play
  209. Inhand.b=0        ;Position in player's hand
  210. Suit.b=0          ;Suit of selected card
  211. Rank.b=0          ;Rank of card selected (A - K)
  212. CSuit.b=0         ;Current suit (s/h/c/d)
  213. CRank.b=0         ;Current rank of card (A - K)
  214. Dcards.b=52       ;Cards left in deck
  215. Dpile.b=0         ;Cards in discard pile
  216. card.b=0          ;Current Card
  217. sx.w=0            ;shape drawing x
  218. sy.w=0            ;shape drawing y
  219. cx.w=16           ;comp. card x
  220. cy.w=40           ;comp. card y
  221. dx.w=0            ;destination x
  222. dy.w=0            ;destination y
  223. sortflag.b=0      ;is player's hand sorted?
  224. rd.w=0            ;colors for fading
  225. bl.w=0
  226. gr.w=0
  227. flip.b=0          ;for turning cards over
  228. flipfrom.b=0
  229. flipto.b=0
  230. up.b=1
  231. down.b=-1
  232. comppull.b=0      ;number of cards computer picked up
  233. compflag.b=0      ;computer's turn
  234. playerflag.b=0    ;player's turn
  235. pickup.b=0        ;number of cards player picked up
  236. Message$=txt$(0)  ;"Written in Blitz"
  237. see.b=0           ;bitmap being viewed
  238. draw.b=0          ;bitmap being drawn on
  239. temp.b=0          ;temporary storage
  240. temp2.b=0
  241. temp3.b=0
  242. paltemp.w=0
  243. ok.b=0            ;is card ok to play?
  244. shp.b=0           ;shape # to be drawn
  245. btn.b=0           ;1=left  2=right mouse button clicked
  246. mx.w=0            ;mouse x position
  247. my.w=0            ;mouse y position
  248. chx.w=0           ;check x
  249. chy.w=0           ;check y
  250. hit.b=0           ;item that was clicked on
  251. check.b=0         ;item being checked
  252. Row.b=1           ;Row selected card is in
  253. Rowflag.b=1       ;Number of rows in players hand
  254. setup.b=0         ;1 if game was already played
  255. replay.b=0
  256. sleep.b=0         ;program is sleeping but start music if = 1 on return
  257. defpa$="data/mods"      ;default path for music module
  258. deffi$="med.moonshine"  ;default mod name
  259.  
  260. Message$="by Curt Esser"
  261.  
  262. Buffer 0,8192     ;set up drawing buffers
  263. Buffer 1,8192     ;for each drawing page
  264. For i = 1 To 52   ;set up the "deck" of cards
  265.   Deck(i)=i
  266. Next
  267.   px.w=15         ;preset positions for
  268.   py.w=128        ;all 50 cards to go
  269. For i = 1 To 50   ;in the player's hand
  270.   If i=26         ;in two horizontal
  271.     px=15         ;rows
  272.     py=162
  273.   EndIf
  274.   Ppos(i,0)=px    ;and store them in
  275.   Ppos(i,1)=py    ;an array
  276.   px+12
  277. Next
  278. draw=1            ;draw on page one
  279. Gosub PrintReq    ;draw localized text onto the "requestors"
  280. .StartScreen      ;now we are ready to go
  281. ShowBitMap 0      ;needed to be sure we are on the right
  282. Use BitMap 0      ;bitmap if game was played before
  283. StopCycle         ;stop the title from flashing
  284. Use Palette pl.b  ;and reset the palette
  285. WPointer 65       ;show the normal game pointer
  286. ;InitPalette 0,8  ;make palette 8 black for fading
  287. For i = 0 To 7    ;set palette 0 to all black again
  288.   PalRGB 0,i,0,0,0;for final fade-out
  289. Next
  290. .StartSc2
  291. Blit 53,160,139   ;show the "SetUp Exit Play"  Requestor
  292. noise=12
  293. Gosub makenoise   ;make sure the player is awake
  294.  
  295. Prequest          ;wait for player to select option
  296.   Gosub getmouse
  297.   If RectsHit(mx,my,1,1,38,109,44,60)  Then Goto Prefs    ;Options
  298.   If RectsHit(mx,my,1,1,238,109,44,60) Then Goto Playgame ;Play
  299.   If RectsHit(mx,my,1,1,149,124,22,30)                    ;Quit
  300.    Gosub MenU                      ;make sure it's not a mistake
  301.    If Split=1 Then Goto split          ;confirmed, so quit game
  302.   EndIf
  303. Goto Prequest                          ;cancelled quit, so try again
  304.  
  305. .MenU                        ;See what they want
  306.   If setup=1                 ;We're on gamescreen
  307.      Message$="????"
  308.      Use BitMap draw
  309.      Gosub PrintMessage
  310.   Else
  311.      VWait 30                ;make sure player sees requestor
  312.   EndIf
  313.   Split=0                    ;default is don't quit
  314.   noise=2:Gosub makenoise
  315.   shp=64:sx=160:sy=139       ;show the "button menu"
  316.   Use BitMap see
  317.   BBlit see,shp,sx,sy        ;on the viewed page
  318.   selection.b=0
  319.   tpl=pl
  320.   Repeat
  321.     Gosub getmouse           ;wait for the response
  322.     If mx>19 AND mx<303 AND my>117 AND my<162
  323.       If mx>19 AND mx<67
  324.         selection=1          ;CONTINUE
  325.         noise = 33
  326.         Gosub makenoise
  327.       EndIf
  328.       ; Button Menu Options:
  329.       If mx>65 AND mx<114    ;Show Score Table
  330.         noise=30
  331.         Gosub makenoise
  332.         Gosub ScoreTable
  333.         ;Request "","Score Table here","OK"
  334.       EndIf
  335.       If mx>113 AND mx<152   ;Change Palette
  336.         noise=13
  337.         Gosub makenoise
  338.         pl+1
  339.         If pl=2 OR pl=3 Then pl=4
  340.         If pl>10 Then pl=1
  341.         fadeto{pl,2}
  342.       EndIf
  343.       If mx>150 AND mx<206   ;Sounds
  344.         noise=24
  345.         Gosub makenoise
  346.         Gosub getSoundPath
  347.         If newsnd$<>snd$ AND newsnd$<>""
  348.           snd$=newsnd$
  349.           showerr.b=True
  350.           Gosub LoadSounds
  351.         EndIf
  352.  
  353.       EndIf
  354.       If mx>205 AND mx<252   ;Music
  355.         noise=29
  356.         Gosub makenoise
  357.         Gosub LoadMed
  358.       EndIf
  359.       If mx>251              ;EXIT
  360.         selection=2
  361.         noise=4
  362.         Gosub makenoise
  363.       EndIf
  364.     Else
  365.       noise=3                ;bad selection
  366.       Gosub makenoise
  367.     EndIf
  368.   Until selection >0
  369.   If selection=2
  370.     Split=1
  371.   ;Else
  372.   ;  VWait 60                 ;hold on a second!
  373.   EndIf
  374.  
  375.   UnBuffer see               ;remove requestor from the screen
  376.   FlushBuffer see            ;and from the buffer too
  377.   Use BitMap draw            ;go back to unseen page to draw
  378.   If Split=0 AND setup=1
  379.     Message$=txt$(2)
  380.     Gosub PrintMessage
  381.   EndIf
  382.  Return
  383.  
  384. .split                         ;exit game
  385.     Message$=txt$(3)
  386.     If setup=1 Then Gosub PrintMessage
  387.     noise=6:Gosub makenoise
  388.     Gosub FinishSound
  389.     Gosub fademusic            ;turn music off
  390.     Free MedModule 0           ;and release the mod's memory
  391.  
  392. split2
  393.  
  394.     noise=19:Gosub makenoise
  395.     fadeto{0,3}                ;fade to black
  396.  
  397.     noise=17:Gosub makenoise   ;a last audio "shot"
  398.     If Forced >0               ;fix screenmode if it was forced
  399.       Gosub FixMode
  400.     EndIf
  401.     Gosub FinishSound
  402.     Quiet 15                   ;can the sound channels
  403.     End                        ;We're history
  404.  
  405. .Playgame                    ;finally, we can play the game!
  406.   WPointer 67                ;show wait pointer
  407.   gamedone.b=False
  408.   replay=0
  409.   Use BitMap draw            ;make sure we are using the unseen page
  410.   Format "###"               ;set the format for the score table
  411.   a$=txt$(4)
  412.   Boxf 180,62,210,72,3               ;Erase any old text first
  413.   Boxf 108,73,176,99,3               ;and any old names
  414.   FNSOutput draw,1                   ;print on the unseen page
  415.   FNSPrint 1,113,63,a$,0,1           ;print the black shadows first
  416.   FNSPrint 1,113,63,a$,0,1
  417.   FNSPrint 1,112,63,a$,0,1
  418.   FNSPrint 1,112,62,a$,0,7           ;and now the gold text
  419.  
  420.   a$=Str$(maxpoints.w)
  421.  
  422.   FNSPrint 0,203,65,a$,#rightalign,1           ;print the numbers shadows first
  423.   FNSPrint 0,203,64,a$,#rightalign,1
  424.   FNSPrint 0,202,65,a$,#rightalign,1
  425.   FNSPrint 0,202,64,a$,#rightalign,7           ;and now the gold text
  426.                                                                                                                               
  427.  
  428.  
  429.   FNSPrint 1,109,76,compname$,0,1    ;print computer's name
  430.   FNSPrint 1,109,75,compname$,0,1    ;with shadows too
  431.   FNSPrint 1,108,76,compname$,0,1
  432.   FNSPrint 1,108,75,compname$,0,7
  433.   FNSPrint 1,109,89,playername$,0,1  ;and player's name
  434.   FNSPrint 1,109,88,playername$,0,1  ;the same way
  435.   FNSPrint 1,108,89,playername$,0,1
  436.   FNSPrint 1,108,88,playername$,0,7
  437.   Blit 0,232,82                ;the deck
  438.   Gosub Newpage                ;switch pages
  439.   CopyBitMap see,draw          ;and make both pages look the same
  440.   fadeto{pl,1}                 ;and fade in the screen
  441. If setup=0                     ;this is the very first game
  442.   noise=12:Gosub makenoise     ;so make a noise!
  443.   VWait 30
  444. EndIf
  445. FlushEvents
  446.  
  447. .Newhand                       ;set up for new hand
  448.   Gosub showscore              ;update the score
  449.   Gosub showCcards
  450.   If setup=1                   ;if it's not the first game
  451.     Message$=txt$(5)
  452.   EndIf
  453.   setup=1                      ;once we get here set the flag
  454.   Gosub PrintMessage           ;and print the appropriate message
  455.  
  456.   Dcards=52:Pcards=0:Ccards=0:Dpile=0:compflag=0:playerflag=0
  457.  
  458.   For i=1 To 52                ;set up new deck of cards
  459.    Deck(i)=i                   ;in order to start with
  460.   Next
  461.   Gosub Shuffle                ;and shuffle them
  462.   VWait 30
  463.   Gosub Shuffle                ;twice
  464.   For d=1 To 5                 ;deal 5 cards to each player
  465.     Gosub Compget              ;one to each
  466.     Gosub showCcards
  467.     Gosub Playerget            ;in order
  468.   Next
  469.  
  470. Upcard                         ;turn next card up to start game
  471.   Gosub Grabcard               ;get the card
  472.   Repeat
  473.      sx-4                      ;and slide it over
  474.      Gosub Draw
  475.   Until sx=88                  ;into position
  476.   flip=up
  477.   Gosub Flipit                 ;now flip it over
  478.   Dpile+1                      ;and keep track of what's
  479.   Pile(Dpile)=card             ;in the pile
  480.   Gosub WhatCard               ;now convert it from a number
  481.   CSuit=Suit                   ;to the Current Suit
  482.   CRank=Rank                   ;and Current Rank
  483.   Gosub Sorthand                ;sort the player's hand
  484.   If music=1 Then Gosub MusicOn ;and start the music if it's on
  485.   VWait
  486.   noise=27                      ;let user know
  487.   Gosub makenoise               ;we're ready to play
  488.  
  489. ;-------------------------------------------------------------------
  490. ;                         MAIN GAME LOOP
  491. ;-------------------------------------------------------------------
  492.  
  493. .GameLoop
  494.   pickup=0            ;nothing has been picked up yet!
  495.   Message$=txt$(6)
  496.   If Ccards=1 Then Message$=txt$(7)
  497.   Gosub PrintMessage
  498.  
  499. .PlayerTurn
  500.   playerflag=1        ;human's turn
  501.   ok=0
  502.   Gosub getmouse      ;wait for input
  503.   CopyBitMap see,draw ;make sure both pages are the same
  504.   ShowBitMap 0
  505.   Use BitMap 1
  506.   see=0
  507.   draw=1
  508.  
  509.   If hit=0
  510.     Gosub HitWhat     ;OK, what happened?
  511.   EndIf
  512.                                                                                                                               
  513.  
  514.  
  515.   Select hit          ;now deal with the selection
  516.     Case 1            ;clicked deck
  517.       Gosub Playerget ;pick up a card from the deck
  518.       pickup+1        ;count how many cards are picked up this turn
  519.     Case 2            ;player clicked MENU
  520.       Gosub MenU      ;so deal with it
  521.     Case 3            ;player clicked a card
  522.       card=PlayCard   ;ok we'll try to play it
  523.       Gosub WhatCard  ;check if it's a legal play
  524.         If ok=1       ;it is so let user play it
  525.           If card=Phand(Pcards)  ;this card was just picked up
  526.             pickup-1             ;so take it off the count
  527.           EndIf                  ;and maybe we won't need to sort hand
  528.           noise=5:Gosub makenoise
  529.           Gosub Pullcard                    ;pull it out
  530.           Gosub Playcard                    ;and play it
  531.           noise=13:Gosub makenoise
  532.           If Row<>Rowflag Then Gosub MoveUp ;if two rows move one card up
  533.           For i=Inhand To Pcards            ;this stuff moves the cards
  534.             Phand(i)=Phand(i+1)             ;over to correct the array
  535.             Next                            ;for the card we took out
  536.           Pcards-1:playerflag=0             ;and correct the count
  537.           If CRank=8 Then Gosub SetSuit     ;choose suit if an 8 played
  538.         Else                 ;go here if the card
  539.           noise=3            ;is not a legal play
  540.           Gosub makenoise    ;let the user know about it
  541.         EndIf                ;and do nothing else
  542.     Case 4                       ;clicked SORT
  543.      If Pcards=1 OR Sortflag=1   ;no need to sort
  544.       noise=16                   ;so we'll make
  545.       Gosub makenoise            ;a sound instead
  546.       VWait 10                   ;in fact, let's make
  547.       Gosub makenoise            ;it echo too!
  548.      Else
  549.       Gosub Sorthand    ;ok, we'll sort the hand
  550.      EndIf
  551.     Case 5                       ;player clicked hide
  552.        sleep=2                   ;so set the sleep flag
  553.        If music=1
  554.          sleep=1                 ;make it 1 to restart music later
  555.          music=0                 ;but turn it off now
  556.          StopMed
  557.        End If
  558.        VWait 2
  559.        If Forced>0
  560.          Gosub FixMode
  561.        EndIf
  562.        WBenchToFront_            ;and bring up WorkBench
  563.        ClickButton 0             ;and activate it
  564.        FlushEvents
  565.        hit=0
  566.        Pop Select
  567.        Goto PlayerTurn
  568.     Default             ;player has clicked something else
  569.       noise=3           ;but there IS nothing else!
  570.       Gosub makenoise   ;let 'em know they made a mistake
  571.   End Select
  572.   hit=0
  573.   VWait
  574.   If Split=1 Then Goto split  ;user wants to quit so do it
  575.   If Pcards=0                 ;player has won hand!
  576.      playerflag=1             ;so set the flag
  577.      Goto Handover            ;and end this hand
  578.   EndIf
  579.   If Dcards=0 Then Gosub Reshuffle       ;no cards left - use discards
  580.   If playerflag=1 Then Goto PlayerTurn   ;still player's turn
  581.   If Sortflag=0 AND pickup>0 Then Gosub Sorthand ;if necessary
  582.  
  583.  holdit.b=2                          ;computer's turn now
  584.  Message$=txt$(8)                    ;so greet the player
  585.  WPointer 67                         ;and put up wait pointer
  586.  comppull=0                          ;and reset pickup count
  587.  If Pcards=2 AND Ccards>2            ;player only has 2 cards
  588.    Gosub CompNoise                   ;and we have more so we complain
  589.    Select complain                   ;set a new complaint
  590.     Case 1
  591.       Message$=txt$(9)
  592.     Case 2
  593.       Message$=txt$(10)
  594.     Case 3
  595.       Message$=txt$(11)
  596.     Case 4
  597.       Message$=txt$(12)
  598.     Case 5
  599.       Message$=txt$(13)
  600.     Case 6
  601.       Message$=txt$(14)
  602.     Case 7
  603.       Message$=txt$(15)
  604.     Case 8
  605.       Message$=txt$(16)
  606.     Case 9
  607.       Message$=txt$(17)
  608.    End Select
  609.    Gosub CompComplain
  610.  EndIf
  611.  
  612.  If Pcards=1                         ;now the player only has one card
  613.    Gosub CompNoise
  614.    Select complain                   ;so REALLY whine about it
  615.     Case 1
  616.       Message$=txt$(18)
  617.       noise=20
  618.     Case 2
  619.       Message$=txt$(19)
  620.     Case 3
  621.       Message$=txt$(20)
  622.     Case 4
  623.       Message$=txt$(21)
  624.     Case 5
  625.       Message$=txt$(22)
  626.     Case 6
  627.       Message$=txt$(23)
  628.     Case 7
  629.       Message$=txt$(24)
  630.     Case 8
  631.       Message$=txt$(25)
  632.       noise=22
  633.     Case 9
  634.       Message$=txt$(26)
  635.     End Select
  636.  Gosub CompComplain
  637.  EndIf
  638.  WildHair.b=0
  639.  If CRank=8 AND Pcards=1 AND Rnd(10)>4
  640.    WildHair=1
  641.    pullet.b=Rnd(8)+6
  642.  EndIf
  643. .Computerturn
  644.    ; Chand.b(52,3) ;Computer's Hand (Card,playability,suit,rank)
  645.  
  646.    Gosub PrintMessage     ;let 'em know it's our turn now
  647.    Gosub FinishSound
  648.    ok=0:cplay.b=0:compflag=1:Cspades=0:Chearts=0:Cclubs=0
  649.    Cdiamonds=0            ;reset everything for this turn
  650.    For i=1 To Ccards
  651.      card=Chand(i,0)                         ;this part checks
  652.      Gosub WhatCard                          ;the computer's hand
  653.      If Suit=0 AND Rank<>8 Then Cspades+1    ;for the number of
  654.      If Suit=1 AND Rank<>8 Then Chearts+1    ;cards of each suit
  655.      If Suit=2 AND Rank<>8 Then Cclubs+1     ;so we know what suit to
  656.      If Suit=3 AND Rank<>8 Then Cdiamonds+1  ;pick if we play an 8
  657.  
  658.      mxx=Cspades:Cmost=0             ;this stuff
  659.      If Ccards=1                     ;finds out which suit we have
  660.        mxx=1                         ;the most of so we can pick it
  661.        If Chearts=1 Then Cmost=1     ;if we played an 8
  662.        If Cclubs=1 Then Cmost=2      ;if 2 or more are equal, we'll
  663.        If Cdiamonds=1 Then Cmost=3   ;randomly pick one of them
  664.      Else
  665.        If Chearts>mxx OR (Chearts=mxx AND Rnd(2)>1)
  666.          Cmost=1
  667.          mxx=Chearts
  668.        EndIf
  669.        If Cclubs>mxx OR (Cclubs=mxx AND Rnd(2)>1)
  670.          Cmost=2
  671.          mxx=Cclubs
  672.        EndIf
  673.        If Cdiamonds>mxx OR (Cdiamonds=mxx AND Rnd(2)>1) Then Cmost=3
  674.      EndIf
  675.  
  676.      Chand(i,1)=0                  ;not playable
  677.      Chand(i,2)=Suit
  678.      Chand(i,3)=Rank
  679.      If ok=1
  680.        If Rank<>8                  ;if the card is a legal play
  681.          Chand(i,1)=1
  682.        Else
  683.          Chand(i,1)=-1             ;8 flag
  684.        EndIf
  685.      EndIf
  686.       ;If ok=1 AND (Pcards>1 OR Ccards=1 OR Rank=CRank) Then Chand(i,1)=1 ;card is a legal play
  687.    Next
  688.    For i = 1 To Ccards              ;OK, now score play desirability
  689.      If Chand(i,1)>0                ;only on playable cards, of course!
  690.        If Chand(i,2)=Cmost
  691.          Chand(i,1)+1               ;have most of this suit!
  692.        EndIf
  693.        For j = 1 To Ccards
  694.          If j<>i AND Chand(j,1)<>-1
  695.            If Chand(i,3)=Chand(j,3) ;same Rank as another card in our hand!
  696.              Chand(i,1)+1
  697.            EndIf
  698.          EndIf
  699.        Next
  700.      EndIf
  701.    Next
  702.    Compeight=0
  703.    Best.b=1
  704.    For i=1 To Ccards
  705.      If Chand(i,1)=>Best
  706.        Best=Chand(i,1)
  707.        cplay=i      ;ok, we will play this one
  708.      EndIf
  709.      If Chand(i,1)=-1
  710.        Compeight+1
  711.      EndIf
  712.    Next
  713.    If WildHair AND comppull<pullet Then cplay=0 ;try for an 8 to block a win
  714.    If (cplay=0 AND (Ccards<Compeight*2+1 OR Pcards<=Compeight OR Pcards=1)) OR Dcards<2 OR Ccards=Compeight ;OR Pcards<(Ccards/2
  715.      For i=1 To Ccards               ;no non-8's to play
  716.       If Chand(i,1)=-1 Then cplay=i  ;so play an 8 if we have one
  717.      Next                            ;unless we're way ahead
  718.    EndIf                             ;we'll save the 8 and draw
  719.    If Pcards>4 AND Ccards>2 AND cplay
  720.      If Rnd(30) > 28 Then cplay=0    ;just a bit of randomness to throw 'em off
  721.    EndIf
  722.    If cplay>0                        ;we're going to play a card
  723.       If comppull=0 AND Ccards=1     ;if it's our last card
  724.        noise=10:Gosub makenoise      ;let 'em know
  725.        Gosub FinishSound
  726.       EndIf
  727.     Gosub CompPlay                 ;play it!
  728.  
  729.     Gosub Playcard                ;alright, play it already!
  730.     If Rank=8 Then Gosub SetSuit  ;ok an 8! Set our suit!
  731.     If Ccards=1                   ;we only have one card
  732.       noise=11                    ;left so warn the player
  733.       Gosub makenoise
  734.     End If
  735.    EndIf
  736.  
  737.   If cplay=0                      ;we're picking up too
  738.      If comppull>1                ;many un-playable cards
  739.       Gosub CompNoise
  740.       Select complain             ;so moan about it!
  741.        Case 1
  742.         Message$=txt$(27)
  743.        Case 2
  744.         Message$=txt$(28)
  745.        Case 3
  746.         Message$=txt$(29)
  747.        Case 4
  748.         Message$=txt$(30)
  749.        Case 5
  750.         Message$=txt$(31)
  751.        Case 6
  752.         Message$=txt$(32)
  753.        Case 7
  754.         Message$=txt$(33)
  755.        Case 8
  756.         Message$=txt$(34)
  757.        Case 9
  758.         Message$=txt$(35)
  759.       End Select
  760.       Gosub CompComplain
  761.       Gosub PrintMessage
  762.      EndIf
  763.      VWait hold+15
  764.      Gosub Compget                 ;go get another card
  765.      comppull+1
  766.   EndIf
  767.   If Dcards=0                      ;and re-shuffle the discards
  768.    Gosub Reshuffle               ;if the deck is all used up
  769.    VWait 30
  770.   EndIf
  771.   Gosub showCcards
  772.   If cplay=0 AND Dcards>0  Then Goto Computerturn ;still Amiga's turn
  773.   If Ccards=0 Then Goto Handover  ;we won this hand
  774.   compflag=0                      ;we didn't win
  775.   Goto GameLoop                   ;so back to the player
  776.  
  777. .Handover                        ;ok, we managed to finish a hand
  778.   WPointer 67                    ;put up the busy pointer
  779.   Gosub fademusic                ;and can the music
  780.   If playerflag=0                ;computer won
  781.     noise=2                      ;make appropriate noise
  782.     Gosub makenoise
  783.     Message$=txt$(36)            ;and print a message
  784.     Gosub PrintMessage
  785.     Gosub FinishSound
  786.  
  787.     Repeat
  788.       Inhand=Pcards:card=Phand(Inhand)  ;now get the player's cards
  789.       Gosub Pullcard                    ;one at a time
  790.       Gosub Playcard                    ;& put 'em on discard pile
  791.       Gosub Score                       ;and score them
  792.       Pcards-1
  793.     Until Pcards=0                      ;till we got 'em all
  794.   Else                                  ;player won
  795.     Message$=txt$(37)                   ;say it in print
  796.     noise=0                             ;and make a noise
  797.     Gosub makenoise                     ;now print the message
  798.     Gosub PrintMessage                  ;pause for a bit
  799.     Gosub FinishSound
  800.     Repeat                              ;now throw computer's cards
  801.       cplay=Ccards                      ;on the discard pile
  802.       Gosub CompPlay                    ;one at a time
  803.       Gosub Playcard
  804.       Gosub showCcards
  805.       Gosub Score                       ;and score each
  806.     Until Ccards=0                      ;till they're all gone
  807.   EndIf
  808. VWait 50
  809. flip=down
  810. Gosub Flipit       ;turn the deck face down
  811. VWait 20
  812. For i=1 To 2       ;now erase the deck
  813.  Use BitMap draw   ;off both screens
  814.  BlitMode EraseMode
  815.  Blit 68,sx,sy     ;by drawing a blank card
  816.  BlitMode CookieMode
  817.  shp=0             ;but buffer-blit
  818.  Gosub Draw        ;the card-back pic on both pages
  819. Next               ;so we can move it
  820.  noise=18
  821.  Gosub makenoise
  822.  Repeat            ;now slide the discard pile back onto
  823.  sx+4              ;the main deck 4 pixels at a time
  824.  Gosub Draw
  825.  Until sx=232
  826. Gosub Drawdone     ;reset everything for the next time
  827.  
  828. If Cscore=>maxpoints OR Pscore=>maxpoints  ;The game is over!
  829.   gamedone.b=True
  830.   noise=6
  831.   Gosub makenoise
  832.   If (Cscore=>maxpoints AND scoreon.b =0) OR (scoreon=1 AND Pscore =>maxpoints)
  833.     Message$=txt$(38)       ;player won the game message
  834.     pwon.b=True
  835.     cwon.b=False
  836.   Else
  837.     Message$=txt$(39)       ;computer won so print this one
  838.     pwon=False
  839.     cwon=True
  840.   EndIf
  841.   Gosub PrintMessage
  842.   Cscore=0                ;reset scores
  843.   Pscore=0
  844.   Gosub FinishSound
  845.   see=0
  846.   draw=1
  847.   ShowBitMap 0
  848.   Use BitMap 0
  849.   Gosub ScoreTable
  850.   replay=1                   ;set the replay flag
  851.   Goto StartSc2              ;and go back to the beginning
  852. EndIf
  853. Goto Newhand   ;game not over, play another hand
  854.  
  855. .Draw              ;double buffer drawing routine
  856.   ShowBitMap see        ;show the already-drawn page
  857.   VWait                 ;wait for the Vblank
  858.   Use BitMap draw       ;now draw on the unseen page
  859.   UnBuffer draw         ;erase the stuff we drew last time
  860.   BBlit draw,shp,sx,sy  ;buffer-blit specified shape
  861.   Exchange see,draw     ;make this the new viewing page
  862. Return
  863.  
  864. Drawdone                   ;this part simply
  865.   ShowBitMap see        ;resets both drawing pages
  866.   VWait                 ;so they are the same
  867.   CopyBitMap see,draw   ;and clears out both buffers
  868.   FlushBuffer 0         ;so we are ready for the next
  869.   FlushBuffer 1         ;animation
  870.   Use BitMap draw
  871. Return
  872.  
  873. Newpage                    ;this routine switches the
  874.   Exchange see,draw     ;drawing (unseen) and
  875.   ShowBitMap see        ;the veiwing (seen) pages
  876.   VWait                 ;so we don't have to do it
  877.   Use BitMap draw       ;by hand all the time
  878. Return
  879.  
  880. .Flipit       ;this makes card flipping animation
  881.   flipfrom=54:flipto=57    ;flip shapes from face down to face up
  882.   If flip=down Then Exchange flipfrom,flipto  ;do in reverse if needed
  883.   For i=flipfrom To flipto Step flip     ;draw the shapes one
  884.     shp=i                                ;per frame till they
  885.     Gosub Draw                           ;are all done
  886.     VWait
  887.   Next
  888.   shp=card                             ;then draw actual card
  889.   If flip=down Then shp=0              ;or card back
  890.   Gosub Draw
  891.   noise=13
  892.   Gosub makenoise
  893.   Gosub Drawdone
  894. Return
  895.  
  896. .Reshuffle                  ; reshuffles the discard pile
  897.    If Dpile=1 Then Return   ; there's only one card - forget it!
  898.    For i=1 To Dpile-1       ; leave the top card out
  899.    Deck(i)=Pile(i)          ; and set up our new deck using
  900.    Next                     ; the rest of the discards
  901.    sx=88:sy=82              ; now slide top card over
  902.    shp=Pile(Dpile)
  903.    Use BitMap draw
  904.    For i=1 To 2
  905.     Blit Pile(Dpile-1),sx,sy  ;first we have to draw
  906.     BBlit draw,shp,sx,sy      ;the next card down in the pile
  907.    Gosub Newpage              ;on both pages under top card
  908.    Next                       ;because it will be seen soon
  909.    For i=1 To 12              ;now we slide the top card
  910.    sx-2                       ;over to the left
  911.    Gosub Draw
  912.    Next
  913.    Gosub Drawdone
  914.    sx=88:sy=82:flip=down:Gosub Flipit ;now flip the "deck" down
  915.    For i=1 To 2                       ;now we need to erase
  916.    BlitMode EraseMode
  917.    Blit 68,sx,sy                      ;both pages under the
  918.    BlitMode CookieMode
  919.    BBlit draw,shp,sx,sy               ;"deck" pic
  920.    Gosub Newpage                      ;actually just 1 card back pic
  921.    Next
  922.    Repeat                      ;now we slide this over to the right
  923.      sx+6
  924.      Gosub Draw
  925.    Until sx=232                ;until it gets to the deck position
  926.    Gosub Drawdone
  927.    sx=64
  928.    shp=Pile(Dpile)             ;now slide the top card back
  929.    BlitMode EraseMode
  930.    Blit 68,sx,sy               ;where it was
  931.    BlitMode CookieMode
  932.    For i=1 To 2
  933.     BlitMode EraseMode
  934.     Blit 68,sx,sy
  935.     BlitMode CookieMode
  936.     BBlit draw,shp,sx,sy
  937.     Gosub Newpage
  938.    Next
  939.    For i=1 To 12
  940.    sx+2
  941.    Gosub Draw
  942.    Next
  943.    Gosub Drawdone
  944.    If CRank=8                  ;and if it's an 8
  945.       Use BitMap see           ;don't forget to draw the
  946.       Blit 60+CSuit,sx,sy      ;selected suit back on it!
  947.       Use BitMap draw
  948.       Blit 60+CSuit,sx,sy
  949.     EndIf
  950.    Dcards=Dpile-1              ;now reset
  951.    Pile(1)=Pile(Dpile)         ;the discard pile
  952.    Dpile=1
  953.  
  954. .Shuffle                       ;shuffle the deck
  955.  If Dcards=1 Then Return       ;only one card - forget it!
  956.  WPointer 67                   ;busy pointer
  957.  Blit 0,230,82                 ;draw two card backs
  958.  Blit 0,234,82                 ;offset from normal position
  959.                                ;but only on one page for animation
  960.   For q=1 To 4                 ;shuffle them 4 times
  961.    For i=1 To Dcards                     ;re-arrainge deck
  962.    Exchange Deck(i),Deck(Rnd(Dcards)+1)  ;at random by exchanging
  963.    Next                                  ;card numbers
  964.    noise=8               ;now make shuffling
  965.    Gosub makenoise       ;sound and
  966.    For i=1 To 20         ;animate by fliping the pages
  967.      ShowBitMap draw     ;back and forth enough times
  968.      VWait               ;to cover the length of the sound
  969.      ShowBitMap see
  970.      VWait               ;the actual shuffling takes no time at all
  971.    Next                  ;this is all for show!
  972.   Next
  973.    Gosub Drawdone
  974.    Return
  975.  
  976. Grabcard         ;pick up the top card on the deck
  977.    If Dcards<1   ;wait a minute! There's no more cards here!
  978.      card=-1     ;so set the flag
  979.      Return      ;and leave
  980.    EndIf
  981.    card=Deck(Dcards)      ;always take the top card
  982.     Dcards-1              ;and subtract one from the deck count
  983.     sx=232                ;set the starting position
  984.     sy=82                 ;for the animation
  985.     shp=0                 ;and set to card-back shape
  986.     If Dcards=0           ;and if this is the last card
  987.      Use BitMap draw      ;erase the deck pic
  988.      For i=1 To 2         ;on both screens
  989.       BlitMode EraseMode
  990.       Blit 68,sx,sy
  991.       BlitMode CookieMode
  992.       BBlit draw,0,sx,sy  ;but buffer-blit the one card back
  993.       Gosub Newpage
  994.      Next
  995.     EndIf
  996.   noise=18                ;ok, make a sound
  997.   Gosub makenoise
  998.   Return
  999.  
  1000. .Compget                     ;pick up a card
  1001.    Gosub Grabcard            ;and send it to the computer's hand
  1002.     Repeat
  1003.       If sx>cx+4 Then sx-4   ;this stuff moves the
  1004.       If sx>cx Then sx-1     ;card toward the next spot in
  1005.       If sx<cx Then sx+2     ;the computer's hand and slows
  1006.       If sy>cy Then sy-1     ;down when it gets close so we
  1007.       shp=0                  ;can hit the exact spot
  1008.       Gosub Draw
  1009.     Until sx=cx AND sy=cy
  1010.    noise=13
  1011.    Gosub makenoise           ;make a sound when it gets there
  1012.    Ccards+1                  ;update the amount of cards
  1013.    Chand(Ccards,0)=card      ;and the computer array
  1014.    cx+6                      ;reset position for next card
  1015.    Gosub Drawdone
  1016.  Return
  1017.  
  1018. .Playerget                   ;player picks up a card
  1019.    Gosub Grabcard            ;get next card from deck
  1020.    If card=-1 Then Return    ;wait a minute-all cards GONE!
  1021.     Pcards+1                 ;add one to our count
  1022.     Sortflag=0               ;and re-set the sort flag
  1023.     Repeat
  1024.       If sx>Ppos(Pcards,0)+4 Then sx-4    ;this slides the card
  1025.       If sx>Ppos(Pcards,0) Then sx-1      ;into the player's hand
  1026.       If sx<Ppos(Pcards,0)-4 Then sx+4    ;just like computer above
  1027.       If sx<Ppos(Pcards,0) Then sx+1
  1028.       If sy<Ppos(Pcards,1) Then sy+2
  1029.       Gosub Draw
  1030.     Until sx=Ppos(Pcards,0) AND sy=Ppos(Pcards,1)
  1031.    Phand (Pcards)=card       ;and update player's array
  1032.    flip=up                   ;but we have to flip the player's
  1033.    Gosub Flipit              ;cards face up so we can see it
  1034.  
  1035.  Return
  1036.  
  1037. .PrintMessage                ;this prints message in message box
  1038.                              ;on the draw page
  1039.  FNSOutput draw,1
  1040.  Boxf 4,185,314,196,3
  1041.  FNSPrint 1,160,186,Message$,#centred,1
  1042.  FNSPrint 1,160,185,Message$,#centred,1
  1043.  FNSPrint 1,159,186,Message$,#centred,1
  1044.  FNSPrint 1,159,185,Message$,#centred,7
  1045.  
  1046. ; copy text from draw to see, 1 line at a time
  1047.  
  1048.  For i = 184 To 197
  1049.   addvaldraw.w=ADDValue(draw,0,i)
  1050.   addvalsee.w=ADDValue(see,0,i)
  1051.   Derez draw,see,addvaldraw,addvalsee,1,1
  1052.   VWait
  1053.  Next
  1054.  Return
  1055.  
  1056. .getmouse       ;wait for a mouseclick or keypress
  1057.   WPointer 65   ;regular pointer
  1058.   FlushEvents $8 ;clear any prior mouse events (for the trigger-happy user)
  1059.   Repeat
  1060.     ev.l=WaitEvent         ;multi-task until response detected
  1061.   Until EventWindow=0
  1062.   If sleep >0              ;program was sleeping (screen hidden)
  1063.      If sleep = 1          ;turn music on
  1064.         If Forced=2        ;force screenmode if it was done before
  1065.           ForcePAL
  1066.         EndIf
  1067.         If Forced=1
  1068.           ForceNTSC
  1069.         EndIf
  1070.         music=1            ;fix the music flag
  1071.         Gosub MusicOn      ;and re-start it
  1072.         sleep=0
  1073.         FlushEvents
  1074.         Goto getmouse
  1075.      EndIf
  1076.   EndIf
  1077.   If ev=$400                     ;key was pressed
  1078.    t$=Inkey$
  1079.    If t$=Chr$(27)                ;ESC key
  1080.      hit=2
  1081.      Return
  1082.    EndIf
  1083.  
  1084.    If t$="p"
  1085.      noise =4
  1086.      Gosub makenoise
  1087.      VWait
  1088.      ForcePAL
  1089.      Forced=2
  1090.    EndIf
  1091.    If t$="n"
  1092.      noise=4
  1093.      Gosub makenoise
  1094.      VWait
  1095.      ForceNTSC
  1096.      Forced=1
  1097.    EndIf
  1098.    If t$="m" OR t$="M"   ;user wants to toggle music off/on
  1099.      If ModOn=1                  ;we have loaded a mod
  1100.        If music=1                ;so do it
  1101.          Gosub fademusic         ;but if off, do it gracefully
  1102.          music=0
  1103.        Else
  1104.          music=1                 ;was off, turn it on
  1105.          Gosub MusicOn           ;put a coin in the jukebox
  1106.        End If
  1107.      Else                        ;NO MOD IN MEMORY!!!
  1108.        ShowBitMap 0
  1109.        Request txt$(60),txt$(63),txt$(64)
  1110.        ShowBitMap see
  1111.      EndIf
  1112.    End If
  1113.    Goto getmouse                 ;go back & wait for mousebutton
  1114.   End If
  1115.  
  1116.  btn=1                    ;left button down
  1117.  If Joyb(0)=2 Then btn=2  ;right button
  1118.  WPointer 66              ;show button down pointer
  1119.  Gosub buttonUp           ;wait till mousebutton is released
  1120.  mx=WMouseX               ;and get the
  1121.  my=WMouseY               ;pointer's position
  1122.  FlushEvents              ;again, save the trigger-happy
  1123. Return                    ;and continue the program
  1124.  
  1125. .buttonUp
  1126.  Repeat                   ;now wait
  1127.    ev.l=WaitEvent         ;for mousebutton
  1128.  Until ev=$8 AND Joyb(0)=0;till it is released
  1129.  WPointer 65              ;use regular pointer
  1130. Return
  1131.  
  1132. HitWhat             ;this determines what was clicked
  1133.   hit=0             ;first we reset the flags
  1134.   PlayCard=0
  1135.   If RectsHit (mx,my,1,1,221,67,22,30) Then hit=1 ; draw a card
  1136.   If RectsHit (mx,my,1,1,257,9,27,9) Then hit=2 ; menu button
  1137.   If RectsHit (mx,my,1,1,225,9,27,9) Then hit=4 ; sort button
  1138.   If RectsHit (mx,my,1,1,290,9,27,9)   Then hit=5 ; hide bitton
  1139.   If hit>0 Then Return  ;Got it! we don't need to check for cards
  1140.   check=1
  1141.   If Pcards=1 Then Goto fullcheck ;only one card left!
  1142.   checkcards   ;checks all the visible card positions from left
  1143.   If RectsHit (mx,my,1,1,Ppos(check,0)-11,Ppos(check,1)-15,11,30)
  1144.     hit=3
  1145.     PlayCard=Phand(check)
  1146.     Inhand=check
  1147.   EndIf
  1148.   check+1
  1149.   If PlayCard=0 AND check <Pcards Then Goto checkcards ;nope, try next
  1150.  
  1151.   fullcheck ;the last card on right is bigger so we check full area
  1152.   If RectsHit (mx,my,1,1,Ppos(check,0)-11,Ppos(check,1)-15,22,30)
  1153.     hit=3
  1154.     PlayCard=Phand(check)
  1155.     Inhand=check
  1156.   EndIf
  1157. Return
  1158.  
  1159. .WhatCard      ;determine the suit & rank of a card from its number
  1160.   Suit=0       ;set to first suit
  1161.   Rank=card    ;this is the card's number
  1162.  
  1163. checksuit
  1164.   If Rank>13        ;only 13 cards per suit
  1165.     Suit+1          ;so go to next suit
  1166.     Rank-13         ;and subtract 13
  1167.     Goto checksuit  ;and try again
  1168.   EndIf
  1169.   ok=0                                              ;now reset flag
  1170.   If Suit=CSuit OR Rank=CRank OR Rank=8 Then ok=1   ;and check for
  1171. Return                                              ;playability
  1172.  
  1173. .Pullcard           ;pull a card out of the player's hand
  1174.   sx=Ppos(Inhand,0)            ;get the drawing positions from
  1175.   sy=Ppos(Inhand,1)            ;the player position array
  1176.   shp=card                     ;and set the drawing shape
  1177.   Row=1:Rowflag=1:temp2=Pcards ;reset the flags to 1 row of cards
  1178.   If Inhand>25 Then Row=2      ;card selected from second row
  1179.   If Pcards>25 Then Rowflag=2  ;player has TWO rows of cards
  1180.   If Row=1 AND Rowflag=2 Then temp2=25  ;but he selected from top row
  1181.   For q=1 To 2                 ;set up both pages
  1182.     BlitMode EraseMode
  1183.     Blit 68,sx,sy              ;draw blank shape to erase
  1184.     BlitMode CookieMode
  1185.     If Inhand>1 AND Inhand<>26 Then Blit Phand(Inhand-1),Ppos(Inhand-1,0),Ppos(Inhand-1,1)
  1186.     BBlit draw,shp,sx,sy       ;and buffer blit the card
  1187.      If Inhand<>Pcards AND Inhand <>25   ;if not last card in row
  1188.       For j= Inhand+1 To temp2           ;re draw other cards to
  1189.         Blit Phand(j),Ppos(j,0),Ppos(j,1);the right of selected one
  1190.       Next
  1191.      EndIf
  1192.    Gosub Newpage              ;and switch pages
  1193.   Next q                      ;do the other page
  1194.    If Inhand=Pcards OR Inhand=25 Then Goto ready ;if last card
  1195.    For i=0 To 12 Step 2       ;otherwise, move cards to right
  1196.      sy-5                     ;over to fill the space
  1197.      Gosub MoveEm
  1198.    Next i
  1199.    i=12
  1200.    Gosub MoveEm
  1201.  
  1202. ready                  ;ok all done
  1203.   ShowBitMap see
  1204.   VWait
  1205.   Use BitMap draw
  1206.   Return
  1207.  
  1208. MoveEm
  1209.      UnBuffer draw
  1210.      BBlit draw,shp,sx,sy
  1211.      BlitMode EraseMode
  1212.      Blit 68,Ppos(temp2,0),Ppos(temp2,1)
  1213.      BlitMode CookieMode
  1214.      For j= Inhand+1 To temp2
  1215.        Blit Phand(j),Ppos(j,0)-i,Ppos(j,1)
  1216.      Next j
  1217.      Gosub Newpage
  1218. Return
  1219.  
  1220. MoveUp
  1221.  temp3=Inhand
  1222.  Inhand=26
  1223.  card=Phand(26)
  1224.  Gosub Pullcard
  1225.  Repeat
  1226.   If sx<Ppos(25,0) Then sx+2
  1227.   If sx<Ppos(25,0)-6 Then sx+4
  1228.   If sx>200 AND  sy<128 Then sy+1
  1229.   If sy>128 Then sy-1
  1230.   Gosub Draw
  1231.  Until sy=128 AND sx=Ppos(25,0)
  1232.  Gosub Drawdone
  1233.  Inhand=temp3
  1234. Return
  1235.  
  1236.  
  1237.  
  1238. .CompPlay
  1239.  cx-6:sx=cx:sy=cy:card=Chand(cplay,0)
  1240.  For i=1 To 2
  1241.    BlitMode EraseMode
  1242.    Blit 68,sx,sy
  1243.    BlitMode CookieMode
  1244.    If Ccards>1 Then Blit 0,sx-6,sy
  1245.    BBlit draw,0,sx,sy
  1246.    Gosub Newpage
  1247.  Next
  1248.  flip=up
  1249.  Gosub Flipit
  1250.  For i=cplay To Ccards
  1251.    Chand(i,0)=Chand(i+1,0)
  1252.  Next
  1253.  For i=1 To 2
  1254.    BlitMode EraseMode
  1255.    Blit 68,sx,sy
  1256.    BlitMode CookieMode
  1257.    If Ccards>1 Then Blit 0,sx-6,sy
  1258.    BBlit draw,card,sx,sy
  1259.    Gosub Newpage
  1260.  Next
  1261.  Ccards-1
  1262. Return
  1263.  
  1264. .SetSuit
  1265.  If Pcards=0 OR Ccards=0 Then Return
  1266.  If compflag=0 AND Sortflag=0 AND pickup>0 Then Gosub Sorthand
  1267.  Message$=txt$(40)  ;"O.K.  Choose Your Suit"
  1268.  If compflag=1
  1269.    If WildHair
  1270.      Message$="WildHair!"
  1271.    Else
  1272.      Message$=txt$(41)  ;"Hmmmmm.  Let's see!"
  1273.    EndIf
  1274.  EndIf
  1275.  Gosub PrintMessage
  1276.  noise=23:Gosub makenoise
  1277.  ShowBitMap draw
  1278.  VWait
  1279.  Use BitMap draw
  1280.  Blit 59,88,82
  1281.  Blit 58,40,82
  1282.  If compflag=1
  1283.   If WildHair AND Cmost=CSuit
  1284.     Cmost+1
  1285.     If Cmost=4 Then Cmost=0
  1286.   EndIf
  1287.   Suit=Cmost
  1288.   Message$=txt$(41)
  1289.   VWait 150
  1290.   Goto useit
  1291.  EndIf
  1292. playerpick
  1293.  Gosub getmouse
  1294.  Suit=5
  1295.  temp=8
  1296.  For i=0 To 3
  1297.   If RectsHit(mx,my,1,1,temp,71,14,15) Then Suit=i
  1298.   temp+15
  1299.   Next
  1300.  If Suit=5
  1301.   noise=3
  1302.   Gosub makenoise
  1303.   Goto playerpick
  1304.  EndIf
  1305.  Message$=txt$(43)
  1306. useit
  1307. Use BitMap see
  1308. Blit 60+Suit,88,82
  1309. CSuit=Suit
  1310. Gosub Drawdone
  1311. noise=5
  1312. Gosub makenoise
  1313. Gosub PrintMessage
  1314. ;VWait 30
  1315. If compflag=1
  1316.    noise=21
  1317. Else
  1318.    noise=26
  1319.    If Pcards<3 Then noise=33
  1320. EndIf
  1321. Gosub makenoise
  1322. VWait 100
  1323. Return
  1324.  
  1325. .Sorthand
  1326.  Rowflag=1
  1327.  If Pcards>25 Then Rowflag=2
  1328.  card=Phand(Pcards)
  1329.  sx=Ppos(Pcards,0)
  1330.  sy=Ppos(Pcards,1)
  1331.  dx=Ppos(1,0)
  1332.  Gosub Slideleft
  1333.  If Rowflag=2
  1334.    sx=Ppos(25,0)
  1335.    sy=Ppos(25,1)
  1336.    card=Phand(25)
  1337.    Gosub Slideleft
  1338.  EndIf
  1339. For i= Pcards+1 To 52
  1340.   Phand(i)=60
  1341. Next
  1342. Sort Phand()
  1343. card=Phand(Pcards)
  1344. sx=Ppos(1,0)
  1345. sy=Ppos(Pcards,1)
  1346. temp=1
  1347. temp2=Pcards
  1348. If Rowflag=2 Then temp=26
  1349. Gosub Slideright
  1350.  If Rowflag=2
  1351.    Rowflag=1
  1352.    sx=Ppos(1,0)
  1353.    sy=Ppos(1,1)
  1354.    card=Phand(25)
  1355.    temp=1
  1356.    temp2=25
  1357.    Gosub Slideright
  1358.  EndIf
  1359. Sortflag=1
  1360. Return
  1361.  
  1362. Slideright
  1363.  flip=up
  1364.  Gosub Flipit
  1365.  noise=18:Gosub makenoise
  1366.  dx=Ppos(temp2,0)
  1367.  If sx<>dx
  1368.   Repeat
  1369.    sx+4
  1370.     For i=temp To temp2
  1371.      If sx>Ppos(i,0) AND sx<Ppos(i,0)+20 Then Blit Phand(i),Ppos(i,0),Ppos(i,1)
  1372.     Next
  1373.    Blit card,sx,sy
  1374.    Gosub Newpage
  1375.   Until sx=dx
  1376.  EndIf
  1377.  Gosub Drawdone
  1378. Return
  1379.  
  1380. Slideleft
  1381.  noise=18:Gosub makenoise
  1382.  If sx<>dx
  1383.   Repeat
  1384.    BlitMode EraseMode
  1385.    Blit 68,sx+3,sy
  1386.    BlitMode CookieMode
  1387.    sx-3
  1388.    Blit card,sx,sy
  1389.    Gosub Newpage
  1390.   Until sx=dx
  1391.  EndIf
  1392.  Gosub Drawdone
  1393.  flip=down
  1394.  Gosub Flipit
  1395. Return
  1396.  
  1397. .Score
  1398.  VWait 15
  1399.  card=shp
  1400.  Gosub WhatCard
  1401.  If Rank>10 Then Rank=10
  1402.  If Rank=1
  1403.     Rank=20
  1404.     noise=1+15*playerflag
  1405.     Gosub makenoise
  1406.   EndIf
  1407.  If Rank=8
  1408.     Rank=50
  1409.     noise=7+3*playerflag
  1410.     Gosub makenoise
  1411.   EndIf
  1412.  noise=14+playerflag
  1413.  Gosub makenoise
  1414.   If (playerflag=0 AND scoreon=0) OR (playerflag=1 AND scoreon=1)
  1415.    Pscore=Pscore+Rank
  1416.   Else
  1417.    Cscore=Cscore+Rank
  1418.   EndIf
  1419.  
  1420. showscore            ;update the score box
  1421.  Format "000"        ;with three number format
  1422.  BitMapOutput see    ;just use the seen page
  1423.  Colour 7,1          ;gold on black
  1424.  Locate 23,9.9
  1425.  Print Str$(Cscore)  ;Computer's score
  1426.  Locate 23,11
  1427.  Print Str$(Pscore)  ;Player's score
  1428.  Gosub Drawdone
  1429.  VWait 35
  1430.  Return
  1431.  
  1432. .showCcards           ;show computer cards in hand
  1433.   Format "00"         ;use two number format
  1434.   BitMapOutput see    ;use the seen page
  1435.   Colour 7,1          ;gold on black
  1436.   Locate 2,.8
  1437.   Print Str$(Ccards)  ;how many cards we're holding
  1438.   BitMapOutput draw   ;use the unseen page
  1439.   Locate 2,.8
  1440.   Print Str$(Ccards)  ;how many cards we're holding
  1441.   VWait hold+1           ;and make sure it's seen
  1442. Return
  1443.  
  1444.  
  1445. .Playcard
  1446.  Repeat
  1447.   If sx<84 Then sx+4
  1448.   If sx<88 Then sx+1
  1449.   If sx>92 Then sx-4
  1450.   If sx>88 Then sx-1
  1451.   If sy>85 Then sy-3
  1452.   If sy>82 Then sy-1
  1453.   If sy<80 Then sy+2
  1454.   If sy<82 Then sy+1
  1455.   Gosub Draw
  1456.   Until sx=88 AND sy=82
  1457.   Gosub Drawdone
  1458.   Dpile+1
  1459.   Pile(Dpile)=card
  1460.   Gosub WhatCard
  1461.   CSuit=Suit
  1462.   CRank=Rank
  1463. Return
  1464.  
  1465. .Prefs              ;Options window w/GT gadgets
  1466. t$=txt$(48)+"|"+txt$(49)
  1467. #ModString   = 51
  1468. #BtnSave     = 52
  1469. #ModReq      = 54
  1470. #Music       = 55
  1471. #SndFilter   = 56
  1472. #LoseWinMX   = 58
  1473. #ScoreMX     = 59
  1474. #BtnUse      = 60
  1475. #Pname       = 61
  1476. #Cname       = 62
  1477. GTString    0,#ModString,70,53,200,16,txt$(44),#PLACETEXT_LEFT,200,ld$
  1478. GTButton    0,#BtnSave,8,169,81,16,txt$(45),#PLACETEXT_IN
  1479. GTButton    0,#ModReq,270,53,19,16,"?",#PLACETEXT_IN
  1480. GTCheckBox  0,#Music,26,79,26,11,txt$(46),#PLACETEXT_RIGHT
  1481. GTCheckBox  0,#SndFilter,202,79,26,11,txt$(47),#PLACETEXT_RIGHT
  1482. GTMX        0,#LoseWinMX,46,116,17,9,"",#PLACETEXT_RIGHT,t$,scoreon.b
  1483. GTMX        0,#ScoreMX,208,113,17,9,"",#PLACETEXT_RIGHT," 50|100|150|200|300",scbtn.b
  1484. GTButton    0,#BtnUse,228,169,81,16,txt$(50),#PLACETEXT_IN
  1485. GTString    0,#Pname,64,16,85,16,txt$(51),#PLACETEXT_LEFT,8,playername$
  1486. GTString    0,#Cname,214,16,85,16,"Amiga",#PLACETEXT_LEFT,8,compname$
  1487.  
  1488. *gtscr.Screen = Peek.l (Addr Screen(0))
  1489. offy.b = *gtscr\WBorTop + *gtscr\_RastPort\TxHeight +1
  1490. fadeto{0,1}
  1491. Window 1,0,0,320,200,$1100,"Crazy Prefs  --  version 2.5",1,2
  1492. WCls 3
  1493. WPointer 65
  1494. noise=28:Gosub makenoise
  1495. offx.b = WLeftOff
  1496. AttachGTList 0,1
  1497. fadeto{pl,1}
  1498. If ModOn.b=1 Then GTSetAttrs  0,#Music, #GTCB_Checked, True
  1499. If Fltr.b=True Then GTSetAttrs  0,#SndFilter, #GTCB_Checked, True
  1500. GTBevelBox 0,7+offx,1+offy,302,35,1
  1501. GTBevelBox 0,7+offx,39+offy,302,56,1
  1502. GTBevelBox 0,7+offx,98+offy,302,66,1
  1503. WJam 0
  1504. WColour 1,0
  1505. WLocate 28,104 : Print txt$(52)
  1506. WLocate 198,102 : Print txt$(53)
  1507. WColour 2,0
  1508. WLocate 138,43 : Print txt$(54)
  1509. WLocate 115,6 : Print txt$(55)
  1510.  
  1511. ; --- Kick 2.00 compatible GTGetInteger and GTGetString commands
  1512. ; ---
  1513. ; --- GTGetStr GTList#, gadid   (GTGetString replacement)
  1514. ; ---
  1515. Function.s GTGetStr{lst.w, gdt.w}
  1516.   *gad.Gadget = GTGadPtr(lst, gdt)
  1517.   *si.StringInfo = *gad\SpecialInfo
  1518.   a$= Peek$(*si\_Buffer)
  1519.   Function Return a$
  1520. End Function
  1521. split=0
  1522. .prefloop
  1523. Repeat
  1524.   ev.l = WaitEvent
  1525.  
  1526.   If ev = #IDCMP_GADGETUP OR ev= #IDCMP_GADGETDOWN
  1527.     noise=13:Gosub makenoise
  1528.     If ev=$20
  1529.       Select GadgetHit
  1530.         Case #ScoreMX
  1531.           scbtn=EventCode
  1532.           If scbtn =0 Then maxpoints=50
  1533.           If scbtn =1 Then maxpoints=100
  1534.           If scbtn=2 Then maxpoints=150
  1535.           If scbtn=3 Then maxpoints=200
  1536.           If scbtn=4 Then maxpoints=300
  1537.         Case #LoseWinMX
  1538.           scoreon=EventCode
  1539.       End Select
  1540.     Else
  1541.       Select GadgetHit
  1542.         Case #ModString
  1543.           newmod$=GTGetStr{0,51}
  1544.           Gosub CheckMed
  1545.         Case #BtnSave
  1546.           compname$=GTGetStr{0,62}
  1547.           playername$=GTGetStr{0,61}
  1548.           Gosub savepref
  1549.           split=1
  1550.         Case #ModReq
  1551.           Gosub LoadMed
  1552.         Case #Music
  1553.           If ModOn=1
  1554.              ModOn=0
  1555.              StopMed
  1556.              music=0
  1557.              Free MedModule 0
  1558.              DetachGTList 0
  1559.              GTDisable 0,#ModReq
  1560.              GTDisable 0,#ModString
  1561.              AttachGTList 0,1
  1562.           Else
  1563.              ModOn=1
  1564.              ld$=pa$+"/"+fi$
  1565.              LoadMedModule 0,ld$
  1566.              music=1
  1567.              Gosub MusicOn
  1568.              DetachGTList 0
  1569.              GTEnable 0,#ModReq
  1570.              GTEnable 0,#ModString
  1571.              AttachGTList 0,1
  1572.           EndIf
  1573.  
  1574.  
  1575.         Case #SndFilter
  1576.           If Fltr=True
  1577.              Fltr=False
  1578.           Else
  1579.              Fltr=True
  1580.           EndIf
  1581.           Gosub setflt
  1582.         Case #BtnUse
  1583.           split=1
  1584.           compname$=GTGetStr{0,62}
  1585.           playername$=GTGetStr{0,61}
  1586.       End Select
  1587.     EndIf
  1588.   EndIf
  1589.   FlushEvents
  1590. Until split
  1591. ;If split=0 Then Goto prefloop
  1592. split=0
  1593. VWait
  1594. Use Window 0
  1595. fadeto{0,1}
  1596. DetachGTList 0
  1597. Free Window 1
  1598. Free GTList 0
  1599. Goto Playgame
  1600.  
  1601. .LoadMed
  1602. ld$=defmed$
  1603. newmod$=ASLFileRequest$(txt$(56),pa$,fi$,0,0,320,200)
  1604. .CheckMed
  1605. If newmod$<>""
  1606.   If ReadFile(0,newmod$)
  1607.     FileInput 0
  1608.     A$ = Edit$(12)    ; Read 12 bytes or upto a chr$(10)
  1609.     CloseFile 0
  1610.     Use Window 0
  1611.     If Left$(A$,3)= "MMD" AND Right$(A$,1) = "4"  ; OK, 4 channel MED
  1612.       size.l=FileSize(newmod$)                    ;check mod length
  1613.       If music=1 Then Gosub fademusic
  1614.       Free MedModule 0                          ;can old mod
  1615.       VWait 10
  1616.       chips.l=ChipFree                          ;check chip mem
  1617.       If chips>size+5000                        ;ok to load new mod
  1618.         ld$=newmod$                             ;so change name
  1619.         defpa$=pa$
  1620.         deffi$=fi$
  1621.         If GadgetHit = #ModReq Then GTSetString 0,#ModString,ld$
  1622.       Else                                      ;short on chip mem!
  1623.         A$=txt$(68)+" = "+Str$(chips)
  1624.         B$=txt$(69)+" "+Str$(size+5000)+"|"+txt$(70)
  1625.         Request A$,B$,txt$(61)
  1626.         pa$=defpa$
  1627.         fi$=deffi$
  1628.       EndIf
  1629.     ld$=pa$+"/"+fi$
  1630.     VWait 10
  1631.     LoadMedModule 0,ld$
  1632.     music=1
  1633.     Gosub MusicOn
  1634.     Else    ; not a 4 channel med!
  1635.       Request txt$(65),txt$(67),txt$(61)
  1636.     EndIf
  1637.   Else      ; can't even find it!
  1638.     Request txt$(65),txt$(66),txt$(64)
  1639.   EndIf
  1640. EndIf
  1641. Return
  1642.  
  1643. .LoadSounds
  1644. snderr.b=0
  1645.  
  1646. For i=0 To 33
  1647.   Timeout(i)=0
  1648.   Free Sound i
  1649.   lsd$=snd$+sd$(i)               ;now load the sounds
  1650.   lnth.l=Exists(lsd$)
  1651.   If lnth>0 AND ChipFree > lnth
  1652.     If ReadFile(0,lsd$)
  1653.       FileInput 0
  1654.       temp$=Inkey$(12)
  1655.       CloseFile 0
  1656.       Use Window 0
  1657.       ;If Right$(temp$,4)="8SVX"
  1658.       If Instr(temp$,"8SVX")
  1659.         LoadSound i,lsd$
  1660.         CacheClearU_
  1661.         ;Request "",Str$(Timeout(i)),"OK"
  1662.         soundnumber.w=i
  1663.         Gosub SoundDelay
  1664.         Timeout(i)=delay.w
  1665.         ;Request "returned",Str$(Timeout(i)),"OK"
  1666.       Else
  1667.         snderr+1
  1668.       EndIf
  1669.     Else
  1670.       snderr+1
  1671.     EndIf
  1672.   Else
  1673.     snderr+1
  1674.   EndIf
  1675. Next
  1676. If snderr>0 AND showerr=True
  1677.   Format ""
  1678.   Request "Crazy 8 sounds",Str$(snderr)+" sounds not loaded","OK"
  1679. EndIf
  1680.  
  1681. Return
  1682.  
  1683. .FinishSound    ;wait until the sound is done
  1684. If hold>0
  1685.   Repeat
  1686.     VWait
  1687.   Until hold=0
  1688. EndIf
  1689. Return
  1690. ;determine the playing time of the samples
  1691.  
  1692. .SoundDelay
  1693.  
  1694. period.q=Peek.w(Addr Sound (soundnumber)+4)     ;get the period from sound object
  1695. lngth.l=(Peek.w(Addr Sound (soundnumber)+6) AND $FFFF)*2  ;get the length from sound object
  1696. frequency.f = 3579440/period                    ;convert to true frequency
  1697. delay.w=lngth/(frequency/vrate)                 ;convert to playing time in VBlanks
  1698. delay+5                                         ;add a bit of padding for short samples
  1699. Return
  1700.  
  1701. .makenoise
  1702. If Timeout(noise)>0
  1703.   SetMedMask 3
  1704.   hold=Timeout(noise)
  1705.   Sound noise,12
  1706. EndIf
  1707. Return
  1708.  
  1709. .fademusic
  1710. For i=64 To 0 Step -1
  1711.   SetMedVolume i
  1712.   VWait 2
  1713. Next
  1714. StopMed
  1715. SetMedVolume 64
  1716. Return
  1717.  
  1718. .MusicOn
  1719.   If ModOn=1 Then StartMedModule 0
  1720. .setflt
  1721.   If Fltr=False
  1722.     Filter On
  1723.   Else
  1724.     Filter Off
  1725.   EndIf
  1726. Return
  1727.  
  1728. .CompComplain           ;complain in print and sound
  1729.     complain=complain + 1         ;and set a new complaint so we
  1730.     If complain>9 Then complain=1 ;don't say the same thing all the time
  1731.     Gosub makenoise
  1732. Return
  1733.  
  1734. .CompNoise
  1735.   Select complain             ;select a noise
  1736.        Case 1
  1737.         noise=25
  1738.        Case 2
  1739.         noise=30
  1740.        Case 3
  1741.         noise=24
  1742.        Case 4
  1743.         noise=29
  1744.        Case 5
  1745.         noise=16
  1746.        Case 6
  1747.         noise=31
  1748.        Case 7
  1749.         noise=1
  1750.        Case 8
  1751.         noise=7
  1752.        Case 9
  1753.         noise=32
  1754.     End Select
  1755. Return
  1756.  
  1757. .savepref
  1758.   If WriteFile (0,"data/8prefs")         ;open pref file
  1759.     FileOutput 0
  1760.     NPrint compname$                     ;computer's name
  1761.     NPrint playername$                   ;player's name
  1762.     NPrint Fltr                          ;audio filter on or off
  1763.     NPrint pa$                           ;default path
  1764.     NPrint fi$                           ;mod name
  1765.     NPrint scbtn                         ;mx scorebutton selected
  1766.     NPrint maxpoints                     ;default top score
  1767.     NPrint scoreon                       ;add points to looser if 0
  1768.     NPrint pl                            ;save the palette
  1769.     NPrint ModOn                         ;use music if 1
  1770.     NPrint snd$
  1771.     CloseFile 0
  1772.     WindowOutput 1
  1773.   Else
  1774.     Request txt$(60),txt$(71),txt$(64)
  1775.   EndIf
  1776. Return
  1777.  
  1778. .loadpref
  1779.   If ReadFile (0,"data/8prefs")          ;open pref file
  1780.     FileInput 0
  1781.     compname$=Edit$(15)                  ;computer's name
  1782.     playername$=Edit$(15)                ;player's name
  1783.     Fltr.b=Edit(6)                         ;audio filter on or off
  1784.     pa$=Edit$(200)                       ;default path
  1785.     fi$=Edit$(200)
  1786.     scbtn.b=Edit(6)                        ;mx scorebutton selected
  1787.     maxpoints.w=Edit(6)                    ;default top score
  1788.     scoreon.b=Edit(6)                      ;add points to looser if 0
  1789.     pl.b=Edit(6)                           ;get the palette
  1790.     ModOn.b=Edit(6)                        ;use music if 1
  1791.     snd$=Edit$(256)                        ;sample path
  1792.     CloseFile 0
  1793.     WindowInput 0
  1794.   Else                                   ;Use Defaults
  1795.     compname$="Amiga"                    ;computer's name
  1796.     playername$=txt$(57)                 ;player's name
  1797.     Fltr.b=False                         ;audio filter on or off
  1798.     pa$="data/Mods"                      ;default path
  1799.     fi$="Med.Moonshine"                  ;default module name
  1800.     scbtn.b=3                            ;mx scorebutton selected
  1801.     maxpoints.w=200                      ;default top score
  1802.     scoreon.b=0                          ;add points to looser if 0
  1803.     ModOn.b=1
  1804.     pl.b=1
  1805.     snd$="sounds/original/"
  1806.   EndIf
  1807.   defpa$=pa$
  1808.   deffi$=fi$
  1809. Return
  1810.  
  1811. .getSoundPath    ;select the Samples directory with a listview
  1812.  
  1813. dirs.w=0                         ;number of entries found
  1814. showme.w=0                       ;the current selection
  1815. drnow$=UnLeft$(Mid$(snd$,8),1)
  1816. drawer$=ourpath$+"/sounds/"
  1817. ChDir drawer$                    ; CD to the sounds/ directory
  1818. ResetList sndDrawers()
  1819. While MoreEntries                ; check if there's any more entries
  1820.   File_Name$=EntryName$          ; get its name
  1821.   If EntryDIR                    ; check if its a directory
  1822.     If File_Name$=drnow$
  1823.       showme=dirs
  1824.     EndIf
  1825.     dirs+1                       ;yes, so increase the directory count
  1826.     If AddItem(sndDrawers())
  1827.       sndDrawers()\string=" "+File_Name$
  1828.     EndIf
  1829.   EndIf
  1830. Wend
  1831. GTTags #GTLV_ShowSelected,0,#GTLV_MakeVisible,showme
  1832. GTListView 2,51,0,0,290,170,"",0,sndDrawers(),showme,0
  1833. AddIDCMP #INTUITICKS
  1834. AddIDCMP #MOUSEMOVE
  1835. VWait
  1836. CacheClearU_
  1837. Window 2,10,20,300,178,$1000," Select a Sample Set:",1,2
  1838. SubIDCMP #INTUITICKS|#MOUSEMOVE
  1839. MenusOff
  1840. AttachGTList 2,2
  1841. Repeat
  1842.   ev.l=WaitEvent
  1843.   If ev=$40
  1844.     showme=EventCode
  1845.   EndIf
  1846. Until ev=$40 AND EventWindow=2
  1847. ResetList sndDrawers()
  1848. For i = 0 To showme
  1849.   dummy=NextItem(sndDrawers())
  1850. Next
  1851. newsnd$=Mid$(sndDrawers()\string,2)
  1852. newsnd$="sounds/"+newsnd$+"/"
  1853. DetachGTList 2
  1854. Free GTList 2
  1855. Free Window 2
  1856. Use Window 0
  1857. ClearList sndDrawers()
  1858. ChDir ourpath$
  1859. Return
  1860.  
  1861. .GetLocale
  1862.   If ReadFile (0,"locale/C8.LOCALE")
  1863.     FileInput 0
  1864.     t$=Edit$(180)
  1865.     If Left$(t$,2)<>"C8" Then Goto badlocale
  1866.     i=0
  1867.     getAnother
  1868.     t$=Edit$(100)
  1869.       txt$(i)=t$
  1870.       i+1
  1871.     If i < 75
  1872.       If NOT Eof(0)
  1873.         Goto getAnother
  1874.       Else
  1875.         Goto badlocale
  1876.       EndIf
  1877.     Else
  1878.       CloseFile 0
  1879.       WindowInput 0
  1880.     EndIf
  1881.     Return
  1882.   EndIf
  1883.  
  1884. badlocale
  1885.   Request "Locale Error","Can't load Locale file|Please read the docs","Darn!"
  1886.   End
  1887.  
  1888. .ScoreTable
  1889.  
  1890. If Exists("c8.scores")         ;read in the saved scores, if any
  1891.   If ReadFile(0,"c8.scores")
  1892.     FileInput 0
  1893.     entries.w=Edit(8)
  1894.     i=1
  1895.     While NOT Eof(0)
  1896.       scorename$(i)=Edit$(30)
  1897.       gamesplayed(i)=Edit(6)
  1898.       gameswon(i)=Edit(6)
  1899.       i+1
  1900.     Wend
  1901.     CloseFile 0
  1902.     WindowInput 0
  1903.     Use Window 0
  1904.   EndIf
  1905. Else
  1906.   entries=2
  1907.   scorename$(1)=playername$
  1908.   scorename$(2)=compname$
  1909. EndIf
  1910.  
  1911. ;fix list to add current names
  1912. temp$=playername$
  1913. exc.b=1
  1914. Gosub addname
  1915. temp$= compname$
  1916. exc=2
  1917. Gosub addname
  1918.  
  1919. ;fix scores
  1920. If gamedone=True
  1921.   For i=1 To entries
  1922.     If scorename$(i)=compname$
  1923.       gamesplayed(i)+1
  1924.       If cwon=True
  1925.         gameswon(i)+1
  1926.       EndIf
  1927.     EndIf
  1928.     If scorename$(i)=playername$
  1929.       gamesplayed(i)+1
  1930.       If pwon=True
  1931.         gameswon(i)+1
  1932.       EndIf
  1933.     EndIf
  1934.   Next
  1935. EndIf
  1936. ;figure % and sort arrays here ----
  1937. For i = 1 To entries
  1938.   If gamesplayed(i)
  1939.     won1.q=(gameswon(i)/gamesplayed(i))*100
  1940.     winpct(i)=Int(won1)
  1941.   Else
  1942.     winpct(i)=0
  1943.   EndIf
  1944. Next
  1945.  
  1946. Repeat             ;sort by number of games played first
  1947.   dummy=0
  1948.   For i = 1 To entries-1
  1949.     If gamesplayed(i)<gamesplayed(i+1)
  1950.       Gosub switchem
  1951.     EndIf
  1952.   Next
  1953. Until dummy=0
  1954.  
  1955.  
  1956. Repeat             ;now sort by winning %
  1957.   dummy=0
  1958.   For i = 1 To entries-1
  1959.     If winpct(i)<winpct(i+1) AND gamesplayed(i)=gamesplayed(i+1)
  1960.       Gosub switchem
  1961.     EndIf
  1962.   Next
  1963. Until dummy=0
  1964.  
  1965.  
  1966. If gamedone=True                   ;save scores to disk
  1967.   If WriteFile (0,"c8.scores")
  1968.     FileOutput 0
  1969.     If entries>30 Then entries=30
  1970.     NPrint entries
  1971.     For i = 1 To entries
  1972.       NPrint scorename$(i)
  1973.       NPrint gamesplayed(i)
  1974.       NPrint gameswon(i)
  1975.     Next
  1976.     CloseFile 0
  1977.     WindowOutput 0
  1978.   Else
  1979.     Request "Disk Error","Can't save scores!","OK"
  1980.   EndIf
  1981. EndIf
  1982. gamedone=False
  1983.  
  1984. ;now we'll make a listview to show the scores
  1985.  
  1986. Dim List MyList.scores(entries + 1)
  1987. Format "##0"
  1988. For i = 1 To entries
  1989.   If AddItem(MyList())
  1990.     temp$=LSet$(scorename$(i),14)
  1991.     lis$=" "+temp$+Str$(gamesplayed(i))+"    "+Str$(gameswon(i))+"    "+Str$(winpct(i))+"%"
  1992.     MyList()\string = lis$
  1993.   EndIf
  1994. Next
  1995. GTListView 2,51,0,0,290,170,"",0,MyList(),0,0
  1996. AddIDCMP #INTUITICKS
  1997. AddIDCMP #MOUSEMOVE
  1998. VWait
  1999. CacheClearU_
  2000. Window 2,10,20,300,178,$1000|$8," Player      Games   Won",1,2
  2001. SubIDCMP #INTUITICKS|#MOUSEMOVE
  2002. MenusOff
  2003. AttachGTList 2,2
  2004. FlushEvents
  2005. Repeat
  2006.   ev.l=WaitEvent
  2007. Until ev=$200 OR ev=$40
  2008. DetachGTList 2
  2009. Free GTList 2
  2010. Free Window 2
  2011. Use Window 0
  2012. FlushEvents
  2013. Return
  2014.  
  2015. switchem
  2016. Exchange scorename$(i),scorename$(i+1)
  2017. Exchange gamesplayed(i),gamesplayed(i+1)
  2018. Exchange gameswon(i),gameswon(i+1)
  2019. Exchange winpct(i),winpct(i+1)
  2020. dummy=1
  2021. Return
  2022.  
  2023. .addname
  2024. gotim.b=False
  2025. For i = 1 To entries
  2026.   If temp$=scorename$(i)
  2027.     i=entries
  2028.     gotim=True
  2029.   EndIf
  2030. Next
  2031. If gotim=False
  2032.   entries+1
  2033.   scorename$(entries)=temp$
  2034.   Exchange scorename$(entries),scorename$(exc)
  2035.   Exchange gamesplayed(entries),gamesplayed(exc)
  2036.   Exchange gameswon(entries),gameswon(exc)
  2037. EndIf
  2038.  
  2039. Return
  2040.  
  2041.  
  2042. .PrintReq              ;this prints Continue & Exit on quit requestor
  2043.  ShapesBitMap 64,3     ;dummy bitmap so we can draw on a shape
  2044.  FNSOutput 3,1         ;send the print to it
  2045.  
  2046.  FNSPrint 1,31,25,txt$(73),#centred,1 ;Continue
  2047.  FNSPrint 1,31,24,txt$(73),#centred,1
  2048.  FNSPrint 1,30,25,txt$(73),#centred,1
  2049.  FNSPrint 1,30,24,txt$(73),#centred,7
  2050.  
  2051.  
  2052.  FNSPrint 1,265,25,txt$(59),#centred,1 ;Quit
  2053.  FNSPrint 1,265,24,txt$(59),#centred,1
  2054.  FNSPrint 1,264,25,txt$(59),#centred,1
  2055.  FNSPrint 1,264,24,txt$(59),#centred,7
  2056.  
  2057.  ShapesBitMap 53,3           ;now the pref-menu-play requestor
  2058.  FNSOutput 3,1               ;send the print to it
  2059.  
  2060.  FNSPrint 1,43,27,txt$(74),#centred,1 ;Prefs
  2061.  FNSPrint 1,43,26,txt$(74),#centred,1
  2062.  FNSPrint 1,42,27,txt$(74),#centred,1
  2063.  FNSPrint 1,42,26,txt$(74),#centred,7
  2064.  
  2065.  FNSPrint 1,142,27,txt$(72),#centred,1 ;Menu
  2066.  FNSPrint 1,142,26,txt$(72),#centred,1
  2067.  FNSPrint 1,141,27,txt$(72),#centred,1
  2068.  FNSPrint 1,141,26,txt$(72),#centred,7
  2069.  
  2070.  
  2071.  
  2072.  FNSPrint 1,243,27,txt$(58),#centred,1 ;Play
  2073.  FNSPrint 1,243,26,txt$(58),#centred,1
  2074.  FNSPrint 1,242,27,txt$(58),#centred,1
  2075.  FNSPrint 1,242,26,txt$(58),#centred,7
  2076.  
  2077.  
  2078.  Return
  2079.  
  2080. .FixMode
  2081.   If ntsSys=True  ;original screen mode
  2082.     ForceNTSC
  2083.   Else
  2084.     ForcePAL
  2085.   EndIf
  2086. Return
  2087.  
  2088.  
  2089.  
  2090. INCDIR ""
  2091. Even
  2092.  
  2093. ;Incbin our font into the compiled file to save effort later
  2094. font_dat: IncBin "C8.FNS"
  2095.  
  2096.